package com.jiangjiang.eshop.membership.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiangjiang.eshop.membership.convert.MemberLevelDetailConvert;
import com.jiangjiang.eshop.membership.dao.MemberLevelDetailMapper;
import com.jiangjiang.eshop.membership.domain.MemberLevelDetailEntity;
import com.jiangjiang.eshop.membership.dto.MemberLevelDetailDTO;
import com.jiangjiang.eshop.membership.dto.MemberLevelDetailPageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName MemberLevelDetailService
 * @Description TODO
 * @Author jhw
 * @Date 2021/8/22 16:25
 * @Version 1.0
 **/
@Service
public class MemberLevelDetailService extends ServiceImpl<MemberLevelDetailMapper, MemberLevelDetailEntity>{

    @Autowired
    private MemberLevelDetailConvert memberLevelDetailConvert;

    /**
     * 用户等级变更明细分页查询
     * @param dto 查询条件
     * @return 查询结果
     */
    public Page<MemberLevelDetailDTO> queryForPage(MemberLevelDetailPageDTO dto){
        Page<MemberLevelDetailEntity> page = new Page<>(dto.getPageNo(), dto.getPageSize(), true);
        LambdaQueryWrapper<MemberLevelDetailEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(MemberLevelDetailEntity::getUserAccountId, dto.getUserAccountId())
                .orderByDesc(MemberLevelDetailEntity::getGmtCreate);
        return memberLevelDetailConvert.convertEntityPage2DTOPage(this.getBaseMapper().selectPage(page, wrapper));
    }


}
